{include file="common/head"/}
<div class="layui-fluid" ng-app="hd" ng-controller="ctrl"><div class="layui-card"><div class="layui-card-body">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>商家管理</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        
        <div class="layui-form-item">
            <label class="layui-form-label">商家名称</label>
                <div class="layui-input-inline">
                <input type="text" name="name" ng-model="field.name" lay-verify="required" placeholder="{:lang('pleaseEnter')}商家名称" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">所属银行</label>
            <div class="layui-input-inline">
                <input type="text" name="bank_name" ng-model="field.bank_name" lay-verify="required" placeholder="所属银行" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">开户行</label>
            <div class="layui-input-inline">
                <input type="text" name="bank_address" ng-model="field.bank_address" lay-verify="required" placeholder="开户行" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">银行卡号</label>
            <div class="layui-input-inline">
                <input type="text" name="bank_no" ng-model="field.bank_no" lay-verify="required" placeholder="银行卡号" class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
            <label class="layui-form-label">收款二维码</label>
            <input type="hidden" name="bank_qrcode" id="bank_qrcode" value="{{field.bank_qrcode}}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="adBtn2"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="adPic2">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>
		<hr />
		
		<div class="layui-form-item">
            <label class="layui-form-label">收款人</label>
            <div class="layui-input-inline">
                <input type="text" name="alipay_username" ng-model="field.alipay_username" lay-verify="required" placeholder="支付宝姓名" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">支付宝账号</label>
            <div class="layui-input-inline">
                <input type="text" name="alipay_account" ng-model="field.alipay_account" lay-verify="required" placeholder="支付宝账号" class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
            <label class="layui-form-label">收款二维码</label>
            <input type="hidden" name="pic" id="pic" value="{{field.pic}}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="adPic">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>
		<hr />
		<div class="layui-form-item">
            <label class="layui-form-label">微信号</label>
            <div class="layui-input-inline">
                <input type="text" name="wechat_account" ng-model="field.wechat_account" lay-verify="required" placeholder="微信账号" class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
            <label class="layui-form-label">微信收款二维码</label>
            <input type="hidden" name="wechat_qrcode" id="wechat_qrcode" value="{{field.wechat_qrcode}}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="adBtn1"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="adPic1">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>
		
		<hr />
		<div class="layui-form-item">
            <label class="layui-form-label">ETH地址</label>
            <div class="layui-input-inline" style='width:300px;'>
                <input type="text" name="eth" ng-model="field.eth" lay-verify="required" placeholder="ETH地址" class="layui-input">
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
                <div class="layui-input-inline">
                <input type="text" name="count" ng-model="field.count" lay-verify="required" placeholder="请输入数量..." class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
            <label class="layui-form-label">单价</label>
                <div class="layui-input-inline">
                <input type="text" name="price" ng-model="field.price" lay-verify="required" placeholder="请输入单价..." class="layui-input">
            </div>
        </div>
		
		<div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
                <div class="layui-input-inline">
                <input type="text" name="phone" ng-model="field.phone" lay-verify="required" placeholder="请输入联系方式..." class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('order')}</label>
                <div class="layui-input-inline">
                <input type="text" name="sort" ng-model="field.sort" value="" placeholder="从小到大排序" class="layui-input">
            </div>
        </div>
       
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
</div>
</div>
{include file="common/foot"/}
<script src="__STATIC__/common/js/angular.min.js"></script>
<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info}'!='null'?{$info}:{type_id:'',id:'',name:'',url:'',open:1,sort:50,pic:'',content:''};
        layui.use(['form', 'layer','upload'], function () {
            var form = layui.form, $ = layui.jquery, upload = layui.upload;
            if($scope.field.pic){
                adPic.src = "__PUBLIC__"+ $scope.field.pic;
            }
			if($scope.field.wechat_qrcode){
                adPic1.src = "__PUBLIC__"+ $scope.field.wechat_qrcode;
            }
			if($scope.field.bank_qrcode){
                adPic2.src = "__PUBLIC__"+ $scope.field.bank_qrcode;
            }
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.id = $scope.field.id;
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#adBtn'
                ,url: '{:url("UpFiles/upload")}'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#adPic').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#pic').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg('上传失败');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
			
			var uploadInst1 = upload.render({
                elem: '#adBtn1'
                ,url: '{:url("UpFiles/upload")}'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#adPic1').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#wechat_qrcode').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg('上传失败');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
			
			var uploadInst2 = upload.render({
                elem: '#adBtn2'
                ,url: '{:url("UpFiles/upload")}'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#adPic2').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#bank_qrcode').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg('上传失败');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
    }]);
</script>